core: new function _ostree_parse_delta_name
authorGiuseppe Scrivano <gscrivan@redhat.com>
Tue, 28 Apr 2015 15:45:37 +0000 (17:45 +0200)
committerGiuseppe Scrivano <gscrivan@redhat.com>
Thu, 7 May 2015 19:58:04 +0000 (21:58 +0200)
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
Makefile-tests.am
src/libostree/ostree-core-private.h
src/libostree/ostree-core.c
tests/test-checksum.c [new file with mode: 0644]

index 7350032f114fbe2fab0a0e83bd8666ffcfb78fe1..6cccb40467b4872ced21e90fd14600430707f9a5 100644 (file)
@@ -112,7 +112,7 @@ noinst_PROGRAMS += tests/test-rollsum
 
 TESTS = tests/test-varint tests/test-ot-unix-utils tests/test-bsdiff tests/test-mutable-tree \
        tests/test-keyfile-utils tests/test-ot-opt-utils tests/test-ot-tool-util \
-       tests/test-gpg-verify-result
+       tests/test-gpg-verify-result tests/test-checksum
 
 check_PROGRAMS =  $(TESTS)
 TESTS_ENVIRONMENT = \
@@ -138,6 +138,10 @@ tests_test_varint_LDADD = $(TESTS_LDADD)
 tests_test_bsdiff_CFLAGS = $(TESTS_CFLAGS)
 tests_test_bsdiff_LDADD = libbsdiff.la $(TESTS_LDADD)
 
+tests_test_checksum_SOURCES = src/libostree/ostree-core.c tests/test-checksum.c
+tests_test_checksum_CFLAGS = $(TESTS_CFLAGS) $(libglnx_cflags)
+tests_test_checksum_LDADD = $(TESTS_LDADD)
+
 tests_test_keyfile_utils_CFLAGS = $(TESTS_CFLAGS)
 tests_test_keyfile_utils_LDADD = $(TESTS_LDADD)
 
index a1584d61f89b656f67894412c9f8e3e9972177be..c3c21b20170de641ba9266764a55a5c34b174181 100644 (file)
@@ -118,6 +118,11 @@ _ostree_get_commitpartial_path (const char *checksum)
   return g_strconcat ("state/", checksum, ".commitpartial", NULL);
 }
 
+void
+_ostree_parse_delta_name (const char  *delta_name,
+                          char        **out_from,
+                          char        **out_to);
+
 void
 _ostree_loose_path (char              *buf,
                     const char        *checksum,
index 3470986323af0c9e411ae6668464149e5ff40c65..f779f89e22c0e1a01840c121929db80b171a4e4d 100644 (file)
@@ -1496,6 +1496,25 @@ _ostree_get_relative_static_delta_part_path (const char        *from,
   return _ostree_get_relative_static_delta_path (from, to, partstr);
 }
 
+void
+_ostree_parse_delta_name (const char  *delta_name,
+                          char        **out_from,
+                          char        **out_to)
+{
+  gs_strfreev char **parts = g_strsplit (delta_name, "-", 2);
+
+  *out_from = *out_to = NULL;
+  if (parts[0] && parts[1])
+    {
+      ot_transfer_out_value (out_from, &parts[0]);
+      ot_transfer_out_value (out_to, &parts[1]);
+    }
+  else
+    {
+      ot_transfer_out_value (out_to, &parts[0]);
+    }
+}
+
 /*
  * file_header_parse:
  * @metadata: A metadata variant of type %OSTREE_FILE_HEADER_GVARIANT_FORMAT
diff --git a/tests/test-checksum.c b/tests/test-checksum.c
new file mode 100644 (file)
index 0000000..80b1343
--- /dev/null
@@ -0,0 +1,63 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
+ *
+ * Copyright (C) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include "libgsystem.h"
+#include <glib.h>
+#include <stdlib.h>
+#include <gio/gio.h>
+#include <string.h>
+#include "ostree-core-private.h"
+
+static void
+test_ostree_parse_delta_name (void)
+{
+  {
+    gs_free char *from;
+    gs_free char *to;
+    _ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d", &from, &to);
+    g_assert_cmpstr (to, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d");
+    g_assert_null (from);
+  }
+
+  {
+    gs_free char *from;
+    gs_free char *to;
+    _ostree_parse_delta_name ("30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d-5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03", &from, &to);
+    g_assert_cmpstr (from, ==, "30d13b73cfe1e6988ffc345eac905f82a18def8ef1f0666fc392019e9eac388d");
+    g_assert_cmpstr (to, ==, "5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03");
+  }
+
+  {
+    gs_free char *from;
+    gs_free char *to;
+    _ostree_parse_delta_name ("", &from, &to);
+    g_assert_null (from);
+    g_assert_null (to);
+  }
+}
+
+int main (int argc, char **argv)
+{
+  g_test_init (&argc, &argv, NULL);
+  g_test_add_func ("/ostree_parse_delta_name", test_ostree_parse_delta_name);
+  return g_test_run();
+}